﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Branch.ascx.cs" Inherits="Admin_UserControls_Branch" %>

<%--<script type="text/javascript">
//    $(function () {
//        $("#divViewBranches").dialog({
//            autoOpen: false,
//            height: 400,
//            width: 700,
//            modal: true
//        });
////        $("#divViewBranches").bind('dialogbeforeclose', OnBeforeViewBranchClose);
//    });

    function ViewBranches() {
        $("#divViewBranches").dialog('open');
//        return false;
    }

    function CloseBranchesModal() {
        $("#divViewBranches").dialog('close');
//        return false;
    }
</script>--%>

<style type="text/css">
/*Modal Popup*/
.modalBackground {
	background-color:Gray;
	filter:alpha(opacity=70);
	opacity:0.7;
}

.modalPopup {
	background-color:#ffffdd;
	border-width:3px;
	border-style:solid;
	border-color:Gray;
	padding:3px;
	width:700px;
}

.modalPopup p {
    padding: 5px;
}


.editButton{ src: url('../../Website/App_Themes/Admin/Images/edit.jpg'); height: 16px; width: 16px; }
</style>

<asp:UpdatePanel ID="upnlBranch" runat="server" UpdateMode="Conditional">
<ContentTemplate>

    <div style="height: 40px; margin-top: 8px;">    
        <asp:Button ID="btnNew" runat="server" Text="New" onclick="btnNew_Click" />
    &nbsp;
        <input id="btnView" type="button" value="View/Edit existing records" runat="server" /><%--onclick="javascript:ViewBranches();"--%>
    </div>

    <table border="0" cellpadding="4" cellspacing="0" width="100%">
    <tr>
    <td class="requiredField" style="width: 90px;">Branch Name:</td>
    <td>
        <asp:TextBox ID="tbBranchName" runat="server"></asp:TextBox>&nbsp;<asp:RequiredFieldValidator
            ID="rfvBranchName" runat="server" ErrorMessage="Enter branch name" Display="Dynamic" ValidationGroup="ValidateForm"
            ForeColor="Red" ControlToValidate="tbBranchName" SetFocusOnError="true"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>Address:</td>
    <td>
        <asp:TextBox ID="tbAddress" runat="server" TextMode="MultiLine" Height="94px" 
            Width="391px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>Phone 1:</td>
    <td>
        <asp:TextBox ID="tbPhone1" runat="server"></asp:TextBox>&nbsp;<asp:RegularExpressionValidator ID="revPhone1" runat="server" 
        ErrorMessage="Invalid phone no." ControlToValidate="tbPhone1" ValidationExpression="^[0-9xX\+\-]*$"
        Display="Dynamic" ValidationGroup="ValidateForm" SetFocusOnError="true" 
        ForeColor="Red"></asp:RegularExpressionValidator>
    </td>
    </tr>
    <tr>
    <td>Phone 2:</td>
    <td>
        <asp:TextBox ID="tbPhone2" runat="server"></asp:TextBox>&nbsp;<asp:RegularExpressionValidator ID="revPhone2" runat="server" 
        ErrorMessage="Invalid phone no." ControlToValidate="tbPhone2" ValidationExpression="^[0-9xX\+\-]*$"
        Display="Dynamic" ValidationGroup="ValidateForm" SetFocusOnError="true" 
        ForeColor="Red"></asp:RegularExpressionValidator>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><%-- colspan="2" class="right"--%>
        <asp:Button ID="btnSave" runat="server" Text="Save" 
            ValidationGroup="ValidateForm" onclick="btnSave_Click" CommandArgument="0" CommandName="InsertBranch" />
    &nbsp;
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" 
            CausesValidation="false" onclick="btnCancel_Click" />
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>
    <div id="divMsg" style="display: none;" class="divMsg" runat="server">
    </div>
    <div id="divErr" style="display: none;" class="divErr" runat="server">
    </div>
    </td>
    </tr>
    </table>


<!-- VIEW SECTION -->
<div id="divViewBranches" style="display: none; padding-bottom: 20px;" class="modalPopup">
<asp:Panel runat="Server" ID="programmaticPopupDragHandle" Style="cursor: move; background-color: #DDDDDD;
    border: solid 1px Gray; color: Black; font-weight: bold;">
    <table border="0" cellpadding="5px" cellspacing="0" width="100%">
    <tr>
    <td style="width: 80%;">View all branches</td>
    <td style="text-align: right; width: 20%;"><%--<a href="#" id="anchorClose" style="color: White; background-color: Red; padding: 1px;" title="Close">&nbsp;X&nbsp;</a>--%>
    <a href="#" id="anchorClose" title="Close" style="border: 0;"><img src="../../Website/App_Themes/Admin/Images/close.jpg" alt="Close" style="background: none; border: 0;" /></a>
    </td>
    </tr>
    </table>
     
</asp:Panel>
    <%--<div style="margin: 15px 0 15px 0;">
        <asp:LinkButton ID="lnkbtnDeleteBranches" runat="server" 
            onclick="lnkbtnDeleteBranches_Click">Delete</asp:LinkButton>
    </div>--%>

    <asp:GridView ID="gvBranches" runat="server" AutoGenerateColumns="False" 
         AllowPaging="True" DataKeyNames="BranchID" 
        Width="100%" onrowcommand="gvBranches_RowCommand" PageSize="10"><%--DataSourceID="sdsBranches"--%>
    <Columns>
        <%--<asp:TemplateField>
        <HeaderTemplate>
            <input id="chkSelectAll" type="checkbox" />
        </HeaderTemplate>
        <ItemTemplate>
            <asp:CheckBox ID="chkSelectRow" runat="server" />  
        </ItemTemplate>
        <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>--%>
        <asp:BoundField DataField="BranchCode" HeaderText="Code" />
        <asp:BoundField DataField="BranchName" HeaderText="Name" />
        <asp:BoundField DataField="BranchPhone1" HeaderText="Phone 1" />
        <asp:BoundField DataField="BranchPhone2" HeaderText="Phone 2" />
        <asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
                <asp:LinkButton ID="lnkbtnEdit" CommandArgument='<%# Eval("BranchID")%>' CommandName="EditBranch"
                    runat="server" ToolTip="Edit">
                    <img alt="Edit" style="background: none; border: 0;" src="../../Website/App_Themes/Admin/Images/edit.jpg" />
                </asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
                <asp:LinkButton ID="lnkbtnDelete" CommandArgument='<%# Eval("BranchID")%>' CommandName="DeleteBranch"
                    runat="server" ToolTip="Delete" OnClientClick="javascript:return confirm('Confirm Delete?');">
                    <img alt="Delete" style="background: none; border: 0;" src="../../Website/App_Themes/Admin/Images/delete.gif" />
                </asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>        
    </Columns>
    <HeaderStyle HorizontalAlign="Left" />
    </asp:GridView>
    <%--<asp:SqlDataSource ID="sdsBranches" runat="server"></asp:SqlDataSource>--%>    
</div>

<ajax:ModalPopupExtender runat="server" ID="mpeViewBranches" BehaviorID="programmaticModalPopupBehavior"
    TargetControlID="btnView" PopupControlID="divViewBranches"
    BackgroundCssClass="modalBackground" DropShadow="True" PopupDragHandleControlID="programmaticPopupDragHandle"
    RepositionMode="RepositionOnWindowScroll" CancelControlID="anchorClose">
</ajax:ModalPopupExtender>
        
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
    <asp:AsyncPostBackTrigger ControlID="gvBranches" EventName="RowCommand" />
    <asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />
    <asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>